<?php
/********************************************************
 *
 * 此文件的作用:
 *		所有新闻的操作
 *
 * @copyright Copyright (c) 2007-12-20
 * @author 刘昌功 lcg635@126.com
 *
 ********************************************************/
defined('APP_DIR') or die('404 Not Found');

FLEA::loadClass('Common_Model');

class Model_Notice extends Common_Model {
	function __construct() {
		parent::Common_Model();
		$this->_tb = FLEA::getSingleton('Table_Notice');
	}

	function getIndexNotice($limit = 10) {
		$cond = 'created <= effectDate';
		$result = $this->_tb->findAll($cond, 'created desc', $limit, 'title, important, created');
		return $result;
	}

	function getList($page, $pageSize = 15) {
		FLEA::loadHelper('pager');
		$fields = 'title, important, author,created, news_id';
		$pager = new FLEA_Helper_Pager($this->_tb, $page, $pageSize, null, 'created desc');
		$lists = $pager->findAll($fields);
		foreach ($lists as $k => $v)
			$lists[$k]['important'] = 1 == $v ? '是' : '否';

		$viewData = array(
			'lists' => $lists,
			'pagerData' => $pager->getPagerData()
		);
		return $viewData;
	}

	function getInfo($nid) {
		$result = $this->_tb->find('notice_id = ' . $nid);
		return $result;
	}

	function insert($row) {
		$resutl = $this->_tb->create($row);
		return $result;
	}

	function update($row) {
		$resutl = $this->_tb->update($row);
		return $result;
	}

	function delete($nid) {
		$resutl = $this->_tb->removeByPkv ($nid);
		return $result;
	}

	function getForm($data = null) {
		return $this->_tb->form($data);
	}
}
